package com.wangjie.product.controller;

import com.wangjie.product.entity.Product;
import com.wangjie.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/{id}")
    public Product getProduct(@PathVariable("id") Long id, HttpServletRequest request) {
        String header = request.getHeader("X-Token");
        log.info("商品id: {}, token: {}", id, header);
        Product product = productService.getProductById(id);
        return product;
    }
}
